/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package framework;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Josh
 */
public class FileManager {
    public static final File FILE_DIRECTORY = new File("files");
    public static final File FMINDEX = new File("fmindex.wat");
    private LinkedList<ImageWrapper> images;
    
    //sets up the file hierarchy if necessary, makes a new index file if necessary, then attempts to read in the serialized linkedlist of
    //image wrappers. If it fails, or no index file existed in the first place, a new index file is made and a new linked list is made
    public FileManager() {
        
        if(!FILE_DIRECTORY.exists())
            FILE_DIRECTORY.mkdir();
        
        if(!FMINDEX.exists()) {
            try {
                FMINDEX.createNewFile();
            } catch (IOException ex) {
                Logger.getLogger(FileManager.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            images = new LinkedList<ImageWrapper>();
        }
        else {
            FileInputStream fis;
            ObjectInputStream ois;
            
            try {
                fis = new FileInputStream(FMINDEX);
                ois = new ObjectInputStream(fis);
                
                images = (LinkedList<ImageWrapper>) ois.readObject();
                ois.close();
                fis.close();
            }
            catch(Exception excep) {
                images = new LinkedList<ImageWrapper>();
            }
        }
        
        
        
        
        
    }
    
    
}
